import React, { useEffect, useRef, useState } from 'react'

const PageTimer = () => {
    const [count, setCount] = useState(0)
    let timer = useRef<number>()
    useEffect(()=>{
        timer.current = window.setInterval(()=>setCount(prev=>prev+1), 1000)
    }, [])

    return (
        <div>
            <h2>{count}</h2>
            page timer

            <button onClick={()=>clearInterval(timer.current)}>clear timer</button>
        </div>
    )
}

export default PageTimer